package com.macbulldev.poc.testgin.calculations;

import java.math.BigDecimal;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import com.macbulldev.poc.testgin.domain.PolicyType;
import com.macbulldev.poc.testgin.domain.Scenario;
import com.macbulldev.poc.testgin.domain.TrialGroup;

@Service("calcUtils")
@Configurable
public class CalcUtils 
{
	
	private static final Logger LOGGER = Logger.getLogger(CalcUtils.class);
	
	//Liablity Rounding Utils
	public Long roundLiabilityAmtUp(Long liabilityAmt, Long roundAmt)
	{
		return ( liabilityAmt + roundAmt - 1 ) / roundAmt * roundAmt;
	}
	public Long roundLiabilityAmtDown(Long liabilityAmt, Long roundAmt)
	{
		return liabilityAmt / roundAmt * roundAmt;
	}
	public Long roundLiabilityAmtUpOrDown(Long liabilityAmt, Long roundAmt)
	{
		return ( liabilityAmt + roundAmt/2 ) / roundAmt * roundAmt;
	}
	
	//Premium Rounding Utils
	public BigDecimal roundNone(BigDecimal val){
		return val.setScale(2, BigDecimal.ROUND_DOWN); 
	}
	public BigDecimal roundUp(BigDecimal val){
		return val.setScale(0, BigDecimal.ROUND_UP); 
	}
	public BigDecimal roundDown(BigDecimal val){
		return val.setScale(0, BigDecimal.ROUND_DOWN); 
	}
	public BigDecimal roundUpOrDown(BigDecimal val){
		return val.setScale(0, BigDecimal.ROUND_HALF_UP);
	}
	public BigDecimal round(BigDecimal val, TrialGroup trialGroup)
	{
		BigDecimal retVal = new BigDecimal("0.00");
		if(trialGroup.getRoundingRule().equalsIgnoreCase("none"))
		{
			retVal = roundNone(val);
		}
		if(trialGroup.getRoundingRule().equalsIgnoreCase("up"))
		{
			retVal = roundUp(val);
		}
		if(trialGroup.getRoundingRule().equalsIgnoreCase("down"))
		{
			retVal = roundDown(val);
		}
		if(trialGroup.getRoundingRule().equalsIgnoreCase("upOrDown"))
		{
			retVal = roundUpOrDown(val);
		}
		
		return retVal;
	}
	
	public static void calculationGateway(PolicyType policyType,Scenario scenario)
	{
		if(policyType.getAbbrName().equalsIgnoreCase("ownBasic"))
		{
			
			OwnBasicCalcs obc = new OwnBasicCalcs();
			obc.generateTestCases(scenario);
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownBasicReiss"))
		{
			OwnBasicReissCalcs c = new OwnBasicReissCalcs();
			c.generateTestCases(scenario);
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownCncur"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownCncurReiss"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownFrcls"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownFrclsReiss"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownCncurFrcls"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("ownCncurFrclsReiss"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnBasic"))
		{
			LnBasicCalcs lbc = new LnBasicCalcs();
			lbc.generateTestCases(scenario);
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnBasicReiss"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnSimul"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnSimulReiss"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnRefi"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnExpRefi"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnSimulRefi"))
		{
			
		}
		else if(policyType.getAbbrName().equalsIgnoreCase("lnSimulRefiExpRefi"))
		{
			
		}
		else
		{
			
		
		}
	
	}//end gateway

}
